#ifndef CMDLINEMATCHER_H
#define CMDLINEMATCHER_H

#include <atlstr.h>
#include "..\tdd.h"

class CmdLineMatcher : public TDD::Discriminator
{
	int m_argc;
	char** m_argv;
public:
	CmdLineMatcher(int argc, _In_opt_count_(argc) char **argv)
		: m_argc(argc)
		, m_argv(argv)
	{
		if (argc < 1)
			throw E_INVALIDARG;
		if ((argc > 1) && (argv == NULL))
			throw E_INVALIDARG;
	}
	virtual ~CmdLineMatcher() {}

	bool Matches(const CStringA& str)
	{
		if (m_argc == 1) // first arg is .exe name
			return true; // no other args means "match everything"

		for(int i=1; i<m_argc; ++i)
		{
			if (str.Find(m_argv[i]) == 0)
			{
				int length = (int)strlen(m_argv[i]); // must end on test, class or namespace boundary
				switch(str[length])
				{
				case L'\0':
				case L':':
				case L'.':
					return true;
				default:
					break;
				}
			}
		}
		return false;
	}

private:
	virtual bool WantTest(const TDD::UnitTestInfo& uti)
	{
		return Matches(CStringA(uti.group) + "." + CStringA(uti.testname));
	}
};

#endif
